#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include "Database.h"
#include "Table.h"
#include "Record.h"
#include "Attribute.h"

using namespace std;

BOOST_AUTO_TEST_SUITE( my_suite )

BOOST_AUTO_TEST_CASE( test1 )
{
	Database d;
	BOOST_CHECK( d.dropTable("non_existing_table") == -1 );
}

BOOST_AUTO_TEST_CASE( test2 )
{
	Database d;
	BOOST_CHECK( d.getTables().size() == 0 );
}

BOOST_AUTO_TEST_CASE( test3 )
{
	Database d;
	BOOST_CHECK( d.getTables().size() == 2 );
}

//Erick
BOOST_AUTO_TEST_CASE( getRecordTest1 )
{
	Table t;
	BOOST_CHECK( t.getRecord("non_existing_record") == -1 );
}

BOOST_AUTO_TEST_CASE( getRecordTest2 )
{
	Table t;
	Record r;
	r = "test";
	t.insert(r);
	BOOST_CHECK( t.getRecord("test") == "test" );
}

BOOST_AUTO_TEST_CASE( renameTest1 )
{
	Table t;
	BOOST_CHECK( t.rename("non_existing_record", "new_name") == -1 );
}

BOOST_AUTO_TEST_CASE( renameTest2 )
{
	Table t;
	Attribute a = Attribute("type", "value");
	t.add(a);
	BOOST_CHECK( t.rename("value", "new_name") == 1 );
}

BOOST_AUTO_TEST_CASE( specifyKeyTest1 )
{
	Table t;
	vector<string> emptyVector;
	BOOST_CHECK( t.specifyKey(emptyVector) == -1 );
}

BOOST_AUTO_TEST_CASE( specifyKeyTest2 )
{
	Table t;
	vector<string> testVector;
	testVector.push_back("testName");
	BOOST_CHECK( t.specifyKey(testVector) == 1 );
}

BOOST_AUTO_TEST_CASE( mergeTest1 )
{
	Table t;
	BOOST_CHECK( t.merge(t, nonExistingTable) == -1 );
}

BOOST_AUTO_TEST_CASE( mergeTest2 )
{
	Table t, v;
	BOOST_CHECK( t.merge(t, v) == 1 );
}

BOOST_AUTO_TEST_CASE( joinTest1 )
{
	Table t;
	BOOST_CHECK( t.join(t, nonExistingTable) != t ); //I'm not sure what should be returned in case of bad input
}

BOOST_AUTO_TEST_CASE( joinTest2 )
{
	Table t, v;
	BOOST_CHECK( t.join(t, v) == t ); 
}

BOOST_AUTO_TEST_CASE( sumTest1 )
{
	Table t;
	BOOST_CHECK( t.sum("non_existing_type") == -1 ); 
}

BOOST_AUTO_TEST_CASE( sumTest2 )
{
	Table t;
	Attribute a = Attribute("type", "value");
	t.add(a);
	BOOST_CHECK( t.sum("type") == 1 ); 
}

BOOST_AUTO_TEST_CASE( countTest1 )
{
	Table t;
	BOOST_CHECK( t.count("non_existing_type") == -1 ); 
}

BOOST_AUTO_TEST_CASE( countTest2 )
{
	Table t;
	Attribute a = Attribute("type", "value");
	t.add(a);
	BOOST_CHECK( t.count("type") == 1 ); 
}

BOOST_AUTO_TEST_CASE( minTest1 )
{
	Table t;
	BOOST_CHECK( t.min("non_existing_type") == -1 ); //or != Attribute()?
}

BOOST_AUTO_TEST_CASE( minTest2 )
{
	Table t;
	Attribute a = Attribute("type", "value");
	t.add(a);
	BOOST_CHECK( t.min("type") == Attribute() ); 
}

BOOST_AUTO_TEST_CASE( maxTest1 )
{
	Table t;
	BOOST_CHECK( t.max("non_existing_type") == -1 ); //or != Attribute()?
}


BOOST_AUTO_TEST_CASE( maxTest2 )
{
	Table t;
	Attribute a = Attribute("type", "value");
	t.add(a);
	BOOST_CHECK( t.max("type") == Attribute() ); 
}

BOOST_AUTO_TEST_CASE( deleteQueryTest1 )
{
	Database d;
	Table t;
	d.addTable(t, "t");
	BOOST_CHECK( d.deleteQuery(nonExistingVector, "t", "ANY" ) == -1 ); 
}

BOOST_AUTO_TEST_CASE( deleteQueryTest2 )
{
	Database d;
	Table t;
	d.addTable(t, "t");
	vector<string> select = t.getAttributes();
	BOOST_CHECK( d.deleteQuery(select, "non-existing-table", "ANY" ) == -1 ); 
}

BOOST_AUTO_TEST_CASE( deleteQueryTest3 )
{
	Database d;
	Table t;
	d.addTable(t, "t");
	vector<string> select = t.getAttributes();
	BOOST_CHECK( d.deleteQuery(select, "t", "non-existing-property" ) == -1 ); 
}

BOOST_AUTO_TEST_CASE( deleteQueryTest4 )
{
	Database d;
	Table t;
	d.addTable(t, "t");
	vector<string> select = t.getAttributes();
	BOOST_CHECK( d.deleteQuery(select, "t", "" ) == -1 ); 
}

BOOST_AUTO_TEST_SUITE_END()